//
//  HWWelfareFuncItemView.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/4/2.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWWelfareFuncItemView: UIView {
    var imageView:UIImageView!
    var titleLabel:UILabel!
    var button:UIButton!
    var itemClick:(()->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUI()
        initFrame()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWWelfareFuncItemView {
    private func initUI() -> Void {
        imageView = UIImageView()
        addSubview(imageView)
        
        titleLabel = HWLabel.createLabel(title: "", color: "#333333", font: 12*widthScale)
        titleLabel.textAlignment = .center
        addSubview(titleLabel)
        
        button = UIButton(type: .custom)
        button.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
        addSubview(button)
    }
    
    private func initFrame() -> Void {
        imageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.height.equalTo(45*widthScale)
            make.top.equalTo(13*widthScale)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(imageView.snp.bottom).offset(-2*widthScale)
        }
        
        button.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    @objc func buttonClick(_ button:UIButton) -> Void {
        self.itemClick?()
    }
}
